<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>位置</title>
</head>
<body>
<div>
    <span>地址：</span>
    <span><input id="location" type="text"></span>
</div>

<div>
    <span>经纬度：</span>
    <span><input id="lng" type="text"></span>
    <span><input id="lat" type="text"></span>
</div>
<script type="text/javascript" src="__TMPL__Public/assets/js/jquery.1.12.4.js"></script>
<script src="http://api.map.baidu.com/api?v=3.0&ak=p1dVi5KCcYv1HEgLMtfLcHuNu0TRR97g"></script>
<script type="text/javascript">
    $(function () {
        get_location();
    });

    function get_location() {
        //获取当前位置
        var geolocation = new BMap.Geolocation();
        geolocation.getCurrentPosition(function(r){
            if(this.getStatus() == BMAP_STATUS_SUCCESS){
                mk = new BMap.Marker(r.point);
                getAddress(r.point);
            }else {
                alert('failed'+this.getStatus());
            }
        });
        //获取地址信息，设置地址label
    }

    function getAddress(point){
        var gc = new BMap.Geocoder();
        gc.getLocation(point, function(rs){
            var addComp = rs.addressComponents;
            var address =  addComp.province +  addComp.city + addComp.district + addComp.street + addComp.streetNumber;//获取地址
            $('#location').val(address)
            $('#lng').val(point.lng)
            $('#lat').val(point.lat)
            console.log(address);
        });
    }
</script>
</body>
</html>